#include "StdAfx.h"
#include "ListFileMultiMedia.h"
#include "MultiMediaDlg.h"
IMPLEMENT_DYNAMIC(ListFileMultiMedia,CWnd)

ListFileMultiMedia::ListFileMultiMedia(void)
{
}

ListFileMultiMedia::~ListFileMultiMedia(void)
{
}


BEGIN_MESSAGE_MAP(ListFileMultiMedia, CWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_PLAYLIST, OnLvnItemchangedPlaylist)
END_MESSAGE_MAP()

int ListFileMultiMedia::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	  
	 m_listControlFile.Create(WS_CHILD | WS_VISIBLE,CRect(0, 0, 0,0), this, IDC_PLAYLIST);
     InitPlayList();
	 m_listControlFile.ShowWindow(SW_SHOW);
	
	m_nNumOfPlaylist = 0;
	m_nOldNumNumOfPlaylist = 0;
	return 0;
}

void ListFileMultiMedia::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	CWnd *parent = GetParent();
	CRect rect;
	this->GetClientRect(&rect);
	parent->GetClientRect(&rect);
	CRect rtViewArea(0,rect.top,rect.left+200, rect.bottom-rect.top);
	m_listControlFile.SetWindowPos(parent,0,rtViewArea.top, rtViewArea.left+200, rtViewArea.bottom, SWP_NOZORDER);
	
}
void ListFileMultiMedia::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CWnd::OnPaint() for painting messages
}



BOOL ListFileMultiMedia::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	//CRect rect;
	//GetClientRect(&rect);
	//CBrush myBrush(COLOR_VIEW_AREA);    // dialog background color
	//CBrush *pOld = pDC->SelectObject(&myBrush);
	//BOOL bRes  = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
	//pDC->SelectObject(pOld);    // restore old brush
	//return bRes;

	return CWnd::OnEraseBkgnd(pDC);
}
void ListFileMultiMedia::InitPlayList()

{ 
	CRect rect;
	m_listControlFile.GetClientRect(&rect);
    LVCOLUMN lvColumn;
	int nCol;
	m_listControlFile.SetView(LVS_REPORT);
	m_listControlFile.ModifyStyleEx(0, LVS_REPORT , NULL);
	m_listControlFile.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_ONECLICKACTIVATE);

	lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
	lvColumn.fmt = LVCFMT_CENTER;
	lvColumn.cx = 200;
	lvColumn.pszText = _T("          Play List");
	nCol = m_listControlFile.InsertColumn(0, &lvColumn);

}
void ListFileMultiMedia::AddDataToPlayList(CListCtrl &ctrl, int row, int col, CString str)
{
    LPWSTR pointer; 
	pointer=(LPWSTR)(LPCTSTR)str; 
	LVITEM lv;
	lv.iItem = row;
	lv.iSubItem = col;
	lv.pszText =  pointer;
	lv.mask = LVIF_TEXT;
	if(col == 0)
		ctrl.InsertItem(&lv);
	else
		ctrl.SetItem(&lv); 

}

void ListFileMultiMedia::OnLvnItemchangedPlaylist(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: Add your control notification handler code here
	CMultiMediaDlg multiDlg;
	m_nNumOfPlaylist = multiDlg.ShareInstance()->nCount;
	{
		POSITION p = m_listControlFile.GetFirstSelectedItemPosition();
		while (p)
		{
			
			int nSelected = m_listControlFile.GetNextSelectedItem(p);
			//m_nOldNumNumOfPlaylist = m_nNumOfPlaylist;
			m_nOldNumNumOfPlaylist = m_nNumOfPlaylist;
			m_nNumOfPlaylist = nSelected;
			/*if (m_bIsPlaying)
				m_VideoMng.MultiMedia_Stop();*/
		}
	}
	*pResult = 0;

}
